﻿// <copyright file="Size3D.cs" company="Axelerate Solutions S.A.">
// Copyright (c) Axelerate Solutions S.A.  All rights reserved.
// </copyright>

namespace Axelerate.Silverlight3D.Media.Media3D
{
    using System;
    using System.Net;
    using System.Windows;
    using System.Windows.Controls;
    using System.Windows.Documents;
    using System.Windows.Ink;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Windows.Media.Animation;
    using System.Windows.Shapes;
    using System.ComponentModel;
    
    /// <summary>
    /// File name: Size3D.cs
    /// Company: Axelerate Solutions S.A.
    /// Created By: Daniel Rojas
    /// Created Date: 10/07/2008 18:13:00 h.
    /// Description: Data structure used to describe the size of a three-dimensional object.
    ///   <Modifications>
    ///   </Modifications>
    /// </summary>
    [TypeConverterAttribute(typeof(Size3DConverter))]
    public struct Size3D : IFormattable
    {
        #region Fields
        /// <summary>
        /// Gets or sets the size of the Size3D in the X dimension.
        /// </summary>
        private double mSizeX;

        /// <summary>
        /// Gets or sets the size of the Size3D in the Y dimension.
        /// </summary>
        private double mSizeY;

        /// <summary>
        /// Gets or sets the size of the Size3D in the Z dimension.
        /// </summary>
        private double mSizeZ;
        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the size of the Size3D in the X dimension.
        /// </summary>
        /// <value>Double that specifies the size of the rectangle in the X dimension.</value>
        /// <remarks>Size3D is typically used to represent the bounds of a MeshGeometry3D or Model3D.</remarks>
        public double X
        {
            get
            {
                return mSizeX;
            }
            set
            {
                mSizeX = value;
                //this.mIsEmpty = false;
            }
        }

        /// <summary>
        /// Gets or sets the size of the Size3D in the Y dimension.
        /// </summary>
        /// <value>Double that specifies the size of the rectangle in the Y dimension.</value>
        /// <remarks>Size3D is typically used to represent the bounds of a MeshGeometry3D or Model3D.</remarks>
        public double Y
        {
            get
            {
                return mSizeY;
            }
            set
            {
                mSizeY = value;
                //this.mIsEmpty = false;
            }
        }

        /// <summary>
        /// Gets or sets the size of the Size3D in the Z dimension.
        /// </summary>
        /// <value>Double that specifies the size of the rectangle in the Z dimension.</value>
        /// <remarks>Size3D is typically used to represent the bounds of a MeshGeometry3D or Model3D.</remarks>
        public double Z
        {
            get
            {
                return mSizeZ;
            }
            set
            {
                mSizeZ = value;
                //this.mIsEmpty = false;
            }
        }

        #endregion

        #region Contructors
        
        /// <summary>
        /// Initializes a new instance of the Size3D structure.
        /// </summary>
        /// <param name="x"><typeparamref name="System.Double"/>The X value of the new Size3D structure.</param>
        /// <param name="y"><typeparamref name="System.Double"/>The Y value of the new Size3D structure.</param>
        /// <param name="z"><typeparamref name="System.Double"/>The Z value of the new Size3D structure.</param>
        public Size3D(double x, double y, double z)
        {
            mSizeX = x;
            mSizeY = y;
            mSizeZ = z;
        }
        #endregion

        #region IFormattable Members

        /// <summary>
        /// Convert the Point3D to his string representation.
        /// </summary>
        /// <param name="format">ignored</param>
        /// <param name="formatProvider">ignored</param>
        /// <returns></returns>
        public string ToString(string format, IFormatProvider formatProvider)
        {
            return (String.Format(formatProvider, format, X, Y, Z));
        }

        #endregion

        #region Methods

        /// <summary>
        /// Converts a String representation of a 3-D Size into the equivalent Size3D structure.
        /// </summary>
        /// <param name="source">The String representation of the 3-D Size.</param>
        /// <returns>The equivalent Size3D structure.</returns>
        public static Size3D Parse(string source)
        {
            if (source == "Empty")
            {
                return new Size3D(); //TODO: implement Empty
            }
            else
            {
                string[] parts = source.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                if (parts.Length == 3)
                {
                    double x = double.Parse(parts[0]);
                    double y = double.Parse(parts[1]);
                    double z = double.Parse(parts[2]);
                    return new Size3D(x, y, z);
                }
            }
            throw new Exception("Invalid source string");
        }

        public string ToString(IFormatProvider provider)
        {
            return (String.Format(provider, "{0},{1},{2}", X, Y, Z));
        }

        public override string ToString()
        {
            return (String.Format("{0},{1},{2}", X, Y, Z));
        }

        #endregion
    }
}
